//
//  VideoTypeViewController.m
//  PhoenixNews
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "VideoTypeViewController.h"
#import "AudioTableViewCell.h"
#import "PhoneixNews.pch"
#import "AudioModel.h"
#import "VideoViewController.h"
#import "AudioViewController.h"
@interface VideoTypeViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *QPmutableArray;
@end

@implementation VideoTypeViewController
- (void)dealloc {
    [_tableView release];
    [_QPmutableArray release];
    [_strMW release];
    [_strQP release];
    [_strGirl release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"block"] style:UIBarButtonItemStylePlain target:self action:@selector(leftAction:)];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style: UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:_tableView];
    [_tableView registerClass:[AudioTableViewCell class] forCellReuseIdentifier:@"Cell"];
    [_tableView release];
    [self getData];
    
}
// 点击返回上一页
- (void)leftAction:(UIBarButtonItem *)sender {
    AudioViewController *audio = [[AudioViewController alloc] init];
    [self.navigationController pushViewController:audio animated:YES];
}
#pragma mark -解数剧
- (void)getData {
    
    NSString *str = self.strQP;
    NSString *strMW = self.strMW;
    NSString *strGirl = self.strGirl;
    NSString *strBoutique = self.strBoutique;
    //奇葩
     NSString *QPstr =@"http://c.3g.163.com/nc/video/list/VAP4BFE3U/n/10-10.html";
    // 萌物
     NSString *MWstr = @"http://c.3g.163.com/nc/video/list/VAP4BFR16/n/0-10.html";
    // 美女
     NSString *girl = @"http://c.3g.163.com/nc/video/list/VAP4BG6DL/n/0-10.html";
    // 精品
     NSString *boutique = @"http://c.3g.163.com/nc/video/list/VAP4BGTVD/n/0-10.html";
    if ([self.strQP isEqualToString:QPstr] ) {
        // 奇葩传值
        AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
        [session GET:str parameters:self progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSArray *array = responseObject[@"VAP4BFE3U"];
            self.QPmutableArray = [AudioModel modelHanderWithArray:array];
            [_tableView reloadData];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];

    }else if ([self.strMW isEqualToString:MWstr]) {
        // 萌物传值
        AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
        [session GET:strMW parameters:self progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSArray *array = responseObject[@"VAP4BFR16"];
            self.QPmutableArray = [AudioModel modelHanderWithArray:array];
            [_tableView reloadData];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];

   
    
    }else if ([self.strGirl isEqualToString:girl]) {
        //美女传值
        AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
        [session GET:strGirl parameters:self progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSArray *array = responseObject[@"VAP4BG6DL"];
            self.QPmutableArray = [AudioModel modelHanderWithArray:array];
            [_tableView reloadData];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];

    }else if ([self.strBoutique isEqualToString:boutique]) {
        // 精品传值
        AFHTTPSessionManager *session = [AFHTTPSessionManager manager];
        [session GET:strBoutique parameters:self progress:^(NSProgress * _Nonnull downloadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            NSArray *array = responseObject[@"VAP4BGTVD"];
            self.QPmutableArray = [AudioModel modelHanderWithArray:array];
            [_tableView reloadData];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];

    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _QPmutableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    AudioModel *audio = _QPmutableArray[indexPath.row];
   
    AudioTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    
    
        [cell.VideoImage sd_setImageWithURL:[NSURL URLWithString:audio.cover]];
    
    [cell.buttonImage setImage:[UIImage imageNamed:@"buttonImage"] forState:UIControlStateNormal];
     return cell;
        
    }
// cell点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    AudioModel *audio = _QPmutableArray[indexPath.row];
    VideoViewController *video = [[VideoViewController alloc] init];
    video.urlStr = audio.mp4_url;
    [self.navigationController pushViewController:video animated:YES];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 400;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
